package com.liyl.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DaLeTouUtils {

    public static String getDaLeTou() {
        //前区list集合
        List<Integer> list1 = new ArrayList<>();
        //后区list集合
        List<Integer> list2 = new ArrayList<>();
        //前区1-35，随机五个不重复
        while (list1.size() < 5) {
            int a = (int) (Math.random() * 35 + 1);
            if (!list1.contains(a)) {
                list1.add(a);
            }
        }
        //按升序排列
        Collections.sort(list1);
        //后区1-12随机2个不重复
        while (list2.size() < 2) {
            int b = (int) (Math.random() * 12+1);
            if (!list2.contains(b)){
                list2.add(b);
            }
        }
        //按升序排列
        Collections.sort(list2);
        return "[" + listToString(list1, ',') +"]---["+ listToString(list2, ',') + "]";
    }

    public static String listToString(List list, char separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list.size(); i++) {
            sb.append(list.get(i)).append(separator);
        }
        return sb.toString().substring(0,sb.toString().length()-1);
    }
}
